//
//  UserCell.m
//  MedicineBox
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "UserCell.h"
#import "DKNightVersion.h"
#import "UIImageView+NightImage.h"

#import "SaveTools.h"

@interface UserCell ()

@property (nonatomic, retain) UIImageView *picView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UISwitch *switchButton;

@end

@implementation UserCell

- (void)dealloc
{
    [_picView release];
    [_titleLabel release];
    [_switchButton release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [DKNightVersionManager addClassToSet:self.class];
        self.nightBackgroundColor = UIColorFromRGB(0x343434);
        
        self.picView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picView];
        [_picView release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.switchButton = [[UISwitch alloc] init];
        [_switchButton release];
        
    }
    return self;
}
#pragma mark - 
#pragma  mark 自定义cell (一个imageview 一个label)
- (void)layoutSubviews
{
    
    [super layoutSubviews];
    self.switchButton.frame = CGRectMake(self.contentView.frame.size.width - 60, (self.contentView.frame.size.height - 30) / 2, 30, 20);
    [self.switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.picView.frame = CGRectMake(5, 20, 20, 20);
    self.titleLabel.frame = CGRectMake(60, 5, self.contentView.frame.size.width - 60, 50);
    self.titleLabel.textColor = [UIColor grayColor];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    
}

- (void)valueWithIndex:(NSInteger)index
{
    if (index == 0) {
        [self.contentView addSubview:self.switchButton];
    }
    
    NSArray *array = @[@"夜间模式",@"清理缓存",@"我的收藏",@"我的管家",@"帮  助",@"免责声明",@"关于我们"];
    NSArray *nameArray = @[@"night",@"clean",@"collect",@"time",@"help",@"sheng",@"we"];
    self.titleLabel.text = [array objectAtIndex:index];
    self.imageView.image = [self imageWithName:[nameArray objectAtIndex:index]];
    self.imageView.nightImage = [self imageWithName:[nameArray objectAtIndex:index]];

}

- (UIImage *)imageWithName:(NSString *)name
{
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}


#pragma mark -
#pragma mark 夜间模式
- (void)switchAction:(UISwitch *)switchButton
{
    if (switchButton.isOn) {
        [DKNightVersionManager nightFalling];
    }else
    {
        [DKNightVersionManager dawnComing];

    }
    
}


- (void)awakeFromNib {
   
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
